<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>SmartFineReport - Local Test</title>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <!-- <script src="https://cdn.tailwindcss.com"></script> -->
    <link rel="stylesheet" href="./dist/smart-finereport.cjs.min.css" />
    <script src="./dist/smart-finereport.cjs.min.js"></script>
    <!--<script type="module" src="./smart-fr-plugin.js"></script>-->

    <style>
      :root {
        /* Light theme colors */
        --bg-primary: #f0f2f5;
        --bg-secondary: #ffffff;
        --bg-tertiary: #fafafa;
        --bg-table-header: #f2f2f2;
        --text-primary: #333;
        --text-secondary: #555;
        --text-accent: #1890ff;
        --border-primary: #d9d9d9;
        --border-secondary: #e8e8e8;
        --border-table: #ddd;
        --shadow-light: rgba(0, 0, 0, 0.1);
        --shadow-subtle: rgba(0, 0, 0, 0.05);
      }

      [data-theme="dark"] {
        /* Dark theme colors */
        --bg-primary: #0f0f23;
        --bg-secondary: #1a1a2e;
        --bg-tertiary: #16213e;
        --bg-table-header: #0e3460;
        --text-primary: #e6e6e6;
        --text-secondary: #b3b3b3;
        --text-accent: #4da6ff;
        --border-primary: #3a3a5c;
        --border-secondary: #2a2a4a;
        --border-table: #404040;
        --shadow-light: rgba(0, 0, 0, 0.3);
        --shadow-subtle: rgba(0, 0, 0, 0.2);
      }

      body {
        font-family: sans-serif;
        padding: 20px;
        background-color: var(--bg-primary);
        color: var(--text-primary);
        transition: background-color 0.3s ease, color 0.3s ease;
      }

      .theme-toggle {
        position: fixed;
        top: 20px;
        right: 20px;
        background: var(--bg-secondary);
        border: 1px solid var(--border-primary);
        border-radius: 20px;
        padding: 8px 16px;
        cursor: pointer;
        font-size: 14px;
        color: var(--text-primary);
        transition: all 0.3s ease;
        z-index: 1000;
      }

      .theme-toggle:hover {
        background: var(--bg-tertiary);
      }

      #report-mock {
        border: 1px solid var(--border-primary);
        padding: 20px;
        margin-bottom: 20px;
        background-color: var(--bg-secondary);
        border-radius: 8px;
        box-shadow: 0 2px 8px var(--shadow-light);
        transition: all 0.3s ease;
      }

      #report-mock h2 {
        text-align: center;
        margin-bottom: 25px;
        font-size: 24px;
        color: var(--text-primary);
      }

      .grid-container {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 20px;
      }

      .grid-item {
        background-color: var(--bg-secondary);
        padding: 20px;
        border: 1px solid var(--border-secondary);
        border-radius: 5px;
        box-shadow: 0 1px 3px var(--shadow-subtle);
        transition: all 0.3s ease;
      }

      .grid-item.chart-large {
        grid-column: span 2;
      }

      .grid-item.table-full {
        grid-column: span 3;
      }

      .kpi {
        text-align: center;
      }

      .kpi h4 {
        margin: 0 0 10px 0;
        font-size: 1em;
        color: var(--text-secondary);
      }

      .kpi p {
        margin: 0;
        font-size: 2em;
        font-weight: bold;
        color: var(--text-accent);
      }

      .chart h4,
      .table-container h4 {
        margin-top: 0;
        margin-bottom: 15px;
        color: var(--text-primary);
      }

      .chart canvas {
        max-width: 100%;
        height: auto;
      }

      table {
        width: 100%;
        border-collapse: collapse;
      }

      th,
      td {
        border: 1px solid var(--border-table);
        padding: 12px;
        text-align: left;
        color: var(--text-primary);
        transition: all 0.3s ease;
      }

      th {
        background-color: var(--bg-table-header);
        font-weight: 600;
      }

      tbody tr:nth-child(odd) {
        background-color: var(--bg-tertiary);
      }

      h1 {
        color: var(--text-primary);
        transition: color 0.3s ease;
      }
    </style>
  </head>
  <body>
    <button class="theme-toggle" onclick="toggleTheme()">🌙 暗黑模式</button>
    <h1>本地测试环境</h1>
    <div id="report-mock">
      <!-- The trigger button is now injected by the script -->
      <h2>销售分析仪表板</h2>
      <div class="grid-container">
        <div class="grid-item kpi">
          <h4>总销售额</h4>
          <p>¥1,234,567</p>
        </div>
        <div class="grid-item kpi">
          <h4>平均订单价值</h4>
          <p>¥890.12</p>
        </div>
        <div class="grid-item kpi">
          <h4>新客户</h4>
          <p>1,234</p>
        </div>
        <div class="grid-item chart chart-large">
          <h4>月度销售趋势</h4>
          <canvas id="salesTrendChart"></canvas>
        </div>
        <div class="grid-item chart">
          <h4>产品类别分布</h4>
          <canvas id="productCategoryChart"></canvas>
        </div>
        <div class="grid-item table-full table-container">
          <h4>区域销售明细</h4>
          <table>
            <thead>
              <tr>
                <th>区域</th>
                <th>销售额</th>
                <th>同比增长</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td>华东</td>
                <td>¥450,000</td>
                <td style="color: green">+12%</td>
              </tr>
              <tr>
                <td>华北</td>
                <td>¥320,000</td>
                <td style="color: green">+8%</td>
              </tr>
              <tr>
                <td>华南</td>
                <td>¥280,000</td>
                <td style="color: red">-2%</td>
              </tr>
              <tr>
                <td>华西</td>
                <td>¥180,000</td>
                <td style="color: green">+15%</td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>

    <script>
      // Theme toggle functionality
      function toggleTheme() {
        const body = document.body;
        const themeToggle = document.querySelector(".theme-toggle");
        const currentTheme = body.getAttribute("data-theme");

        if (currentTheme === "dark") {
          body.removeAttribute("data-theme");
          themeToggle.innerHTML = "🌙 暗黑模式";
          localStorage.setItem("theme", "light");
        } else {
          body.setAttribute("data-theme", "dark");
          themeToggle.innerHTML = "☀️ 明亮模式";
          localStorage.setItem("theme", "dark");
        }
      }

      // Initialize theme from localStorage
      function initTheme() {
        const savedTheme = localStorage.getItem("theme");
        const body = document.body;
        const themeToggle = document.querySelector(".theme-toggle");

        if (savedTheme === "dark") {
          body.setAttribute("data-theme", "dark");
          themeToggle.innerHTML = "☀️ 明亮模式";
        } else {
          body.removeAttribute("data-theme");
          themeToggle.innerHTML = "🌙 暗黑模式";
        }
      }

      // Chart.js Initialization
      document.addEventListener("DOMContentLoaded", function () {
        // Initialize theme
        initTheme();
        // Sales Trend Chart (Bar)
        const salesCtx = document
          .getElementById("salesTrendChart")
          .getContext("2d");
        new Chart(salesCtx, {
          type: "bar",
          data: {
            labels: ["一月", "二月", "三月", "四月", "五月", "六月"],
            datasets: [
              {
                label: "月度销售额 (万元)",
                data: [65, 59, 80, 81, 56, 55],
                backgroundColor: "rgba(24, 144, 255, 0.6)",
                borderColor: "rgba(24, 144, 255, 1)",
                borderWidth: 1,
              },
            ],
          },
          options: {
            responsive: true,
            scales: {
              y: {
                beginAtZero: true,
              },
            },
          },
        });

        // Product Category Chart (Pie)
        const productCtx = document
          .getElementById("productCategoryChart")
          .getContext("2d");
        new Chart(productCtx, {
          type: "pie",
          data: {
            labels: ["电子产品", "家居用品", "户外运动", "图书音像"],
            datasets: [
              {
                label: "产品类别分布",
                data: [300, 150, 100, 80],
                backgroundColor: [
                  "rgba(255, 99, 132, 0.7)",
                  "rgba(54, 162, 235, 0.7)",
                  "rgba(255, 206, 86, 0.7)",
                  "rgba(75, 192, 192, 0.7)",
                ],
                hoverOffset: 4,
              },
            ],
          },
          options: {
            responsive: true,
          },
        });
      });
    </script>
  </body>
</html>
